package com.zx.feign.client.fallbackfactory;

import com.zx.core.wrapper.ObjectWrapper;
import com.zx.feign.client.SystemClient;
import com.zx.feign.client.dto.GetLoginUserResponseDTO;
import com.zx.feign.client.dto.GetSysUserResponseDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * <p>
 * description:  降级工厂,好处是可以拿到异常<br>
 * create: 2025-04-23 10:03 <br>
 * </p>
 *
 * @author zhou  xun
 */
@Slf4j
@Component
public class SystemClientFallbackFactory implements FallbackFactory<SystemClient> {
    @Override
    public SystemClient create(Throwable cause) {
        return new SystemClient() {
            @Override
            public ObjectWrapper<GetLoginUserResponseDTO> getUserInfo(String userName) {
                log.error("getUserInfo远程调用被限流或降级了", cause);
                ObjectWrapper<GetLoginUserResponseDTO> response = new ObjectWrapper<>();
                response.fail("getUserInfo远程调用被限流或降级了");
                return response;
            }

            @Override
            public ObjectWrapper<GetSysUserResponseDTO> getUserInfoById(String userId) {
                log.error("getUserInfoById远程调用被限流或降级了", cause);
                ObjectWrapper<GetSysUserResponseDTO> response = new ObjectWrapper<>();
                response.fail("getUserInfoById远程调用被限流或降级了");
                return response;
            }
        };
    }
}
